home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Science / RLaB / rlib / lyap.r < prev    next >
Text File  |  1994-04-25  |  1KB  |  58 lines

  1. //-------------------------------------------------------------------//
  2. // lyap.r:
  3. //
  4. // Syntax:    lyap ( A , B , C )
  5. //        lyap ( A ,   , C )
  6. //
  7. // Description:
  8. //
  9. // lyap solves the general form of the Lyapunov (Sylvester) equation:
  10. //
  11. //    A*X + X*B = -C
  12. //
  13. // To solve the special form of the Lyapunov equation:
  14. //
  15. //    A*X + X*A' = -C
  16. //
  17. // Skip the second argument when using lyap (`lyap (A,,C)').
  18.  
  19. // See Also: schur, sylv
  20. //-------------------------------------------------------------------//
  21.  
  22. lyap = function ( A, B, C )
  23. {
  24.   local (X, sa, sb, tc)
  25.  
  26.   if (!exist (B)) 
  27.   { 
  28.     B = A';    // Solve the special form: A*X + X*A' = -C
  29.   }
  30.  
  31.   if ((A.nr != A.nc) || (B.nr != B.nc) || (C.nr != A.nr) || (C.nc != B.nr)) {
  32.     error ("Dimensions do not agree.");
  33.   }
  34.  
  35.   //
  36.   // Schur decomposition on A and B
  37.   //
  38.  
  39.   sa = schur (A);
  40.   sb = schur (B);
  41.  
  42.   //
  43.   // transform C
  44.   //
  45.  
  46.   tc = sa.z' * C * sb.z;
  47.  
  48.   X = sylv (sa.t, sb.t, tc);
  49.  
  50.   //
  51.   // Undo the transformation
  52.   //
  53.  
  54.   X = sa.z * X * sb.z';
  55.  
  56.   return X;
  57. };
  58.